package com.ktg.mes.erpUnitMeasure.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.ktg.mes.erpUnitMeasure.entity.T6ErpUnitMeasure;
import com.ktg.mes.erpUnitMeasure.mapper.T6ErpUnitMeasureMapper;
import com.ktg.mes.erpUnitMeasure.service.IT6ErpUnitMeasureService;
import com.ktg.mes.md.domain.MdUnitMeasure;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 存货分类
 * @Author: jeecg-boot
 * @Date:   2022-08-12
 * @Version: V1.0
 */
@Service
@DS("erp-datasource")
public class T6ErpUnitMeasureServiceImpl extends ServiceImpl<T6ErpUnitMeasureMapper, T6ErpUnitMeasure> implements IT6ErpUnitMeasureService {

    @Override
    public List<T6ErpUnitMeasure> queryList() {
        return this.list();
    }

    @Override
    public List<T6ErpUnitMeasure> queryListByLastPubufts(Long pubufts) {
        List<T6ErpUnitMeasure> srcList = this.baseMapper.queryListByLastPubufts(pubufts);
//        List<MdUnitMeasure> distList = srcList.stream().map(item -> toMdUnitMeasure(item)).collect(Collectors.toList());
        return srcList;
    }

    public MdUnitMeasure toMdUnitMeasure(T6ErpUnitMeasure srcItem) {
        MdUnitMeasure dist = new MdUnitMeasure();
        dist.setMeasureCode(srcItem.getCComunitCode());
        dist.setMeasureName(srcItem.getCComUnitName());
        dist.setPrimaryFlag(srcItem.getBMainUnit() == 1 ? "Y" : "N");
        if (srcItem.getIChangRate() != null) {
            dist.setChangeRate(new BigDecimal(srcItem.getIChangRate()));
        }
        dist.setEnableFlag("Y");
        dist.setPubufts(srcItem.getPubufts());
        return dist;
    }


}
